/**
 * 静态方法
 * Name = platformHelper
 * DateTime = Wed Jan 19 2022 00:09:27 GMT+0800 (中国标准时间)
 * Author = Created by zhj9922
 * FileBasename = platformHelper.ts
 * gitee： https://gitee.com/coyeking
 */
 
import { _decorator, Component, Node,sys } from 'cc';
import { uiManager } from '../framework/uiManager';
const { ccclass, property } = _decorator;
 
@ccclass('platformHelper')
export class platformHelper {
	
    /**
     * 设置剪贴板
     * @param str 
     */
     public static copyStr(str:string):void{
        if (sys.isNative){
            // todo
            return;
        }
        if (sys.isBrowser){
            var input = str + '';
            const el = document.createElement('textarea');
            el.value = input;
            el.setAttribute('readonly', '');
            el.style.contain = 'strict';
            el.style.position = 'absolute';
            el.style.left = '-9999px';
            el.style.fontSize = '12pt'; // Prevent zooming on iOS
        
            const selection = getSelection();
            var originalRange = null;
            if (selection.rangeCount > 0) {
                originalRange = selection.getRangeAt(0);
            }
            document.body.appendChild(el);
            el.select();
            el.selectionStart = 0;
            el.selectionEnd = input.length;
        
            var success = false;
            try {
                success = document.execCommand('copy');
            } catch (err) {}
        
            document.body.removeChild(el);
        
            if (originalRange) {
                selection.removeAllRanges();
                selection.addRange(originalRange);
            }
            uiManager.showToast('复制成功');
        }

    }
}

